/*
 * DbExecutor.java
 *
 * Created on January 29, 2007, 10:51 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package ge.info.domain;

import ge.info.domain.currency.Currency;
import ge.info.domain.others.OthersInfo;
import ge.info.domain.schedule.ScheduleItem;
import ge.info.domain.schedule.SchedulePlace;
import ge.info.domain.schedule.ScheduleType;
import ge.info.domain.sport.SportType;
import ge.info.domain.sport.SportPlace;
import ge.info.domain.sport.SportItem;
import ge.info.domain.sport.SportTournament;
import ge.info.domain.transport.Transport;
import ge.info.logging.Session;


import ge.ktools.Utils;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.TreeMap;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Administrator
 */
@Transactional(rollbackFor = Throwable.class)
public class DbExecutor extends SqlMapClientDaoSupport implements DbExecutorIface
{

    public List<TreeMap> getGeoIndMessages(StringString stringString)
    {
        return getSqlMapClientTemplate().queryForList("main.getGeoIndMessages", stringString);
    }

    public List<TreeMap> getChMessages(StringString stringString)
    {

        return getSqlMapClientTemplate().queryForList("main.getChMessages", stringString);

    }

    public List<TreeMap> getSMessages(StringString stringString)
    {

        return getSqlMapClientTemplate().queryForList("main.getSMessages", stringString);

    }

    public String getNoncharge(String ph)
    {
        return (String) getSqlMapClientTemplate().queryForObject("main.getNoncharge",ph);
    }

     public List<TreeMap> getWMessages(StringString stringString)
    {

        return getSqlMapClientTemplate().queryForList("main.getWMessages", stringString);

    }

     public List<TreeMap> getSmsinMessages(StringString stringString)
    {

        return getSqlMapClientTemplate().queryForList("main.getSmsinMessages", stringString);

    }


    public List<TreeMap> getNMessages()
    {

        return getSqlMapClientTemplate().queryForList("main.getNMessages",null);

    }

    public StringString getLotwinner()
    {

        return (StringString) getSqlMapClientTemplate().queryForObject("main.getLotwinner",null);

    }

    public StringString getVerlotwinner()
    {

        return (StringString) getSqlMapClientTemplate().queryForObject("main.getVerlotwinner",null);

    }

    public List<TreeMap> getRMessages(String usnm)
    {

        return getSqlMapClientTemplate().queryForList("main.getRMessages",usnm);

    }

     public List<TreeMap> getMenMessages()
    {

        return getSqlMapClientTemplate().queryForList("main.getMenMessages",null);

    }

    public List<TreeMap> getDistanceMessages(StringString stringString)
    {

        return getSqlMapClientTemplate().queryForList("main.getDistanceMessages", stringString);

    }

    public boolean loginCheck(StringString userNamePassword)
    {
        try {
            Object result = getSqlMapClientTemplate().queryForObject("domain.loginCheck", userNamePassword);
            System.out.println("result = "+result.toString());
            return ((String) result != null);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public List<ScheduleType> getScheduleTypes()
    {
        return (List<ScheduleType>) getSqlMapClientTemplate().queryForList("schedule.getScheduleTypes");
    }

     public List<SportType> getSportTypes()
    {
        return (List<SportType>) getSqlMapClientTemplate().queryForList("sport.getSportTypes");
    }

    public ScheduleType populateSchedulePlaces(ScheduleType st)
    {
        return (ScheduleType) getSqlMapClientTemplate().queryForObject("schedule.getSchedulePlaces", st);
    }

    public SportType populateSportPlaces(SportType st)
    {
        return (SportType) getSqlMapClientTemplate().queryForObject("sport.getSportPlaces", st);
    }

    public ScheduleType searchPosters(ScheduleType st)
    {
        return (ScheduleType) getSqlMapClientTemplate().queryForObject("schedule.searchPosters", st);
    }

    public SportType searchspPosters(SportType st)
    {
        return (SportType) getSqlMapClientTemplate().queryForObject("sport.searchspPosters", st);
    }

    public List<ScheduleType> searchAllPosters(ScheduleType st)
    {
        return getSqlMapClientTemplate().queryForList("schedule.searchPosters", st);
    }

     public List<SportType> searchspAllPosters(SportType st)
    {
        return getSqlMapClientTemplate().queryForList("sport.searchspPosters", st);
    }

    public List<ScheduleItem> getScheduleItems(SchedulePlace sp, ScheduleType st)
    {
        int scType = sp.getScheduleTypeID();
        sp.setScheduleTypeID(st.getServiceID());
        List<ScheduleItem> list = (List<ScheduleItem>) getSqlMapClientTemplate().queryForList("schedule.getScheduleItems", sp);
        sp.setScheduleTypeID(scType);
        return list;
    }

    public List<SportItem> getSportItems(SportPlace sp, SportType st)
    {
        int scType = sp.getSportTypeID();
        sp.setSportTypeID(st.getServiceID());
        List<SportItem> list = (List<SportItem>) getSqlMapClientTemplate().queryForList("sport.getSportItems", sp);
        sp.setSportTypeID(scType);
        return list;
    }

    public List<SportItem> searchspPostersdet(SportItem itm)
    {
        
        return getSqlMapClientTemplate().queryForList("sport.searchspPostersdet", itm);
        
    }


    public List<SportTournament> getSportTournaments(SportPlace sp, SportType st)
    {
        int scType = sp.getSportTypeID();
        sp.setSportTypeID(st.getServiceID());
        List<SportTournament> list = (List<SportTournament>) getSqlMapClientTemplate().queryForList("sport.getSportTournaments", sp);
        sp.setSportTypeID(scType);
        return list;
    }

    public List<Service> getServices()
    {
        return (List<Service>) getSqlMapClientTemplate().queryForList("domain.getServices");
    }

    public List<ServiceDetail> getAllServiceDetails()
    {
        return (List<ServiceDetail>) getSqlMapClientTemplate().queryForList("domain.getAllServiceDetails");
    }

    public void populateServiceDetails(Service service)
    {
        service.setServiceDetails((List<ServiceDetail>) getSqlMapClientTemplate().queryForList("domain.getServiceDetails", service));
    }

    public List<Integer> searchDetails(Service service, Session session, boolean searchDetails)
    {
        List<Integer> results = null;
        setSessionData(session);
        if (service.getAddressSearch() != 0)
        {
            Address address = service.getAddress();
            if (address.getCityID() != null || address.getCityRegion().getRegionID() != 0 || address.getStreetName() != null || address.getSuffix() != null)
            {
                String str = address.getStreetName();
                String suf = address.getSuffix();
                if (str == null && suf == null)
                {
                    address.setSuffix(null);
                } else
                {
                    if (str != null && suf != null)
                    {
                        address.setSuffix(str + " | " + suf);
                    } else
                    {
                        address.setSuffix(str == null ? suf : str);
                    }
                }
                // getSqlMapClientTemplate().insert("domain.logSearchAddress", address);
                address.setStreetName(str);
                address.setSuffix(suf);
            }
        }

//        for (ServiceDetail serviceDetail : service.getServiceDetails())
//        {
//            if (serviceDetail.getCriteria() != null)
//            {
//                getSqlMapClientTemplate().insert("domain.logSearchDetails", serviceDetail);
//            } else
//            {
//                if (serviceDetail.getDateCriteria() != null)
//                {
//                    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy");
//                    serviceDetail.setCriteria(sdf.format(serviceDetail.getDateCriteria()));
//                    getSqlMapClientTemplate().insert("domain.logSearchDetails", serviceDetail);
//                    serviceDetail.setCriteria(null);
//                }
//            }
//        }
        if (searchDetails)
        {
            results = (List<Integer>) getSqlMapClientTemplate().queryForList("domain.searchDetails", service);
        } else
        {
            results = (List<Integer>) getSqlMapClientTemplate().queryForList("domain.searchDetailsShort", service);
        }
        if (results == null)
        {
            results = new ArrayList<Integer>();
        }
        return results;
    }

    public List<Integer> search(Service service)
    {
        List<Integer> results = (List<Integer>) getSqlMapClientTemplate().queryForList("domain.search", service);
        if (results == null)
        {
            results = new ArrayList<Integer>();
        }
        return results;
    }

    public List<MainResult> getMainResults(List<Integer> list)
    {
        if (list == null || list.size() == 0)
        {
            return new ArrayList<MainResult>();
        }
        List<MainResult> results = (List<MainResult>) getSqlMapClientTemplate().queryForList("main.getMainResults", list);
        if (results == null)
        {
            results = new ArrayList<MainResult>();
        }
        return results;
    }

    public void getMainResultDetails(MainResult result, Session session)
    {
        List<MainResultDetail> results = (List<MainResultDetail>) getSqlMapClientTemplate().queryForList("main.getMainResultDetails", result.getMainID());
        if (results == null)
        {
            results = new ArrayList<MainResultDetail>();
        }
        result.setDetails(results);
        result.setAddress((Address) getSqlMapClientTemplate().queryForObject("main.searchAddressByID", result.getMainID()));
    }

    public void logMainResult(int mainID, Session session, Service service)
    {
//        setSessionData(session);
//        HashMap m = new HashMap();
//        m.put("mainID", mainID);
//        m.put("serviceID", service.getServiceID());
//        getSqlMapClientTemplate().insert("main.logMainResult", m);
    }

    public List<AbonentFound> searchInd(AbonentFound af, Session session)
    {
        setSessionData(session);
        List<AbonentFound> list = (List<AbonentFound>) getSqlMapClientTemplate().queryForList("main.searchInd", af);

        HashMap<String, Object> map = new HashMap();
        map.put("firstName", af.getFirstName());
        map.put("lastName", af.getLastName());
        map.put("phone", af.getPhone().getPhone());
        map.put("YM", session.getYearMonth());
        map.put("sessionID", session.getSessionID());


        getSqlMapClientTemplate().insert("logging.logSearchInd", map);
        Address address = af.getAddress();
        if (address.getCityID() != null || address.getCityRegion().getRegionID() != 0 || address.getStreetName() != null || address.getSuffix() != null)
        {
            String str = address.getStreetName();
            String suf = address.getSuffix();
            if (str == null && suf == null)
            {
                address.setSuffix(null);
            } else
            {
                if (str != null && suf != null)
                {
                    address.setSuffix(str + " | " + suf);
                } else
                {
                    address.setSuffix(str == null ? suf : str);
                }
            }
            //    getSqlMapClientTemplate().insert("domain.logSearchAddress", address);
            address.setStreetName(str);
            address.setSuffix(suf);
        }
        if (list == null)
        {
            list = new ArrayList<AbonentFound>();
        } else
        {
            for (AbonentFound a : list)
            {
                //     getSqlMapClientTemplate().insert("main.logFound", a);
            }
        }
        return list;
    }

//    public List<AbonentFound> searchInd(AbonentFound af, Country country)
//    {
//        AbonentFound criteria = new AbonentFound();
//
//        List<AbonentFound> list = (List<AbonentFound>) getSqlMapClientTemplate().queryForList("main.searchIndAbroad", criteria);
//        if (list == null)
//        {
//            list = new ArrayList<AbonentFound>();
//        }
//        return list;
//    }
//    // search bu phone
    public List<AbonentFound> searchIndByPhone(String ph, Session session)
    {


        if (session != null)
        {
            HashMap<String, Object> map = new HashMap();
            map.put("firstName", null);
            map.put("lastName", null);
            map.put("phone", ph);
            map.put("YM", session.getYearMonth());
            map.put("sessionID", session.getSessionID());
            getSqlMapClientTemplate().insert("logging.logSearchInd", map);
        }
        List<AbonentFound> list = (List<AbonentFound>) getSqlMapClientTemplate().queryForList("main.searchIndPhone", ph);
        if (list == null)
        {
            list = new ArrayList<AbonentFound>();
        } else
        {
            for (AbonentFound a : list)
            {
                //  getSqlMapClientTemplate().insert("main.logFound", a);
            }
        }
        return list;
    }

    public List<AbonentFound> searchOrgByPhone(String ph)
    {
        List<AbonentFound> list = (List<AbonentFound>) getSqlMapClientTemplate().queryForList("main.searchOrgPhone", ph);
        if (list == null)
        {
            list = new ArrayList<AbonentFound>();
            return list;
        }
        for (AbonentFound ab : list)
        {
            ab.setOrg(true);
        }
        return list;
    }
 public Street searchStreetdet(int streetID)
    {
        return (Street) getSqlMapClientTemplate().queryForObject("main.searchStreetdet",streetID);
    }
    public List<Street> searchStreet(Street street)
    {
        //setSessionData(session);

        if (street.getStreetName() != null)
        {
            return getSqlMapClientTemplate().queryForList("main.searchStreet", street);
        }
        if (street.getStreetIndex() != null)
        {
            return getSqlMapClientTemplate().queryForList("main.searchStreetShort", street);
        }
        return null;
    }

    public List<Transport> searchTransport(Transport transport, Session session)
    {
        setSessionData(session);
        List<Integer> results = (List<Integer>) getSqlMapClientTemplate().queryForList("transport.searchTransport", transport);

        // getSqlMapClientTemplate().insert("transport.logSearchTransport", transport);
        if (results == null || results.size() == 0)
        {
            return new ArrayList<Transport>();
        } else
        {
            for (Integer integer : results)
            {
                //       getSqlMapClientTemplate().insert("transport.logFound", integer);
            }


            return getSqlMapClientTemplate().queryForList("transport.foundTransports", results);
        }
    }

    public List<Transport> searchTransportByCountry(Transport transport, Session session)
    {
        setSessionData(session);
        //getSqlMapClientTemplate().insert("transport.logSearchTransportByCountry", transport);
        List<Integer> results = (List<Integer>) getSqlMapClientTemplate().queryForList("transport.searchTransportByCountry", transport);
        if (results == null || results.size() == 0)
        {
            return new ArrayList<Transport>();
        } else
        {
            for (Integer integer : results)
            {
                //      getSqlMapClientTemplate().insert("transport.logFound", integer);
            }
            return getSqlMapClientTemplate().queryForList("transport.foundTransports", results);
        }
    }

    public List<Transport> searchTransportStops(Integer id)
    {
        return getSqlMapClientTemplate().queryForList("transport.foundTransportStops", id);
    }

    public List<Transport> searchTransportByNo(Transport transport)
    {
        return getSqlMapClientTemplate().queryForList("transport.searchTransportByNo", transport);
    }

    public List<Transport> searchTransportByRoute(Transport transport)
    {
        return getSqlMapClientTemplate().queryForList("transport.searchTransportByRoute", transport);
    }

    public List<Transport> getRouteParts(Transport transport)
    {
        return getSqlMapClientTemplate().queryForList("transport.getRouteParts", transport);
    }

    

    public void setRates(Currency c1, Currency c2, Session session)
    {
        c1.setRate((Double) getSqlMapClientTemplate().queryForObject("currency.getRate", c1));
        c2.setRate((Double) getSqlMapClientTemplate().queryForObject("currency.getRate", c2));
        HashMap m = new HashMap();
        m.put("service_id", Currency.getServiceID());
        m.put("first_id", c1.getCurrencyID());
        m.put("second_id", c2.getCurrencyID());
        setSessionData(session);
    //getSqlMapClientTemplate().insert("logging.insertPair", m);

    }

    public void setDRates(Currency c1, Currency c2, Session session)
    {
        c1.setRate((Double) getSqlMapClientTemplate().queryForObject("currency.getDRate", c1));
        c2.setRate((Double) getSqlMapClientTemplate().queryForObject("currency.getDRate", c2));
        HashMap m = new HashMap();
        m.put("service_id", Currency.getServiceID());
        m.put("first_id", c1.getCurrencyID());
        m.put("second_id", c2.getCurrencyID());
        setSessionData(session);
    //getSqlMapClientTemplate().insert("logging.insertPair", m);

    }

    //--Kakha
    public void setMrates(Currency c1, Currency c2, Session session)
    {
        c1.setMrate((Double) getSqlMapClientTemplate().queryForObject("currency.getMRate", c1));
        c2.setMrate((Double) getSqlMapClientTemplate().queryForObject("currency.getMRate", c2));
        HashMap m = new HashMap();
        m.put("service_id", Currency.getServiceID());
        m.put("first_id", c1.getCurrencyID());
        m.put("second_id", c2.getCurrencyID());
        setSessionData(session);
    //getSqlMapClientTemplate().insert("logging.insertPair", m);

    }

     public void setDMrates(Currency c1, Currency c2, Session session)
    {
        c1.setMrate((Double) getSqlMapClientTemplate().queryForObject("currency.getDMRate", c1));
        c2.setMrate((Double) getSqlMapClientTemplate().queryForObject("currency.getDMRate", c2));
        HashMap m = new HashMap();
        m.put("service_id", Currency.getServiceID());
        m.put("first_id", c1.getCurrencyID());
        m.put("second_id", c2.getCurrencyID());
        setSessionData(session);
    //getSqlMapClientTemplate().insert("logging.insertPair", m);

    }

    public void setSmrates(Currency c1, Currency c2, Session session)
    {
        c1.setSmrate((Double) getSqlMapClientTemplate().queryForObject("currency.getSMRate", c1));
        c2.setSmrate((Double) getSqlMapClientTemplate().queryForObject("currency.getSMRate", c2));
        HashMap m = new HashMap();
        m.put("service_id", Currency.getServiceID());
        m.put("first_id", c1.getCurrencyID());
        m.put("second_id", c2.getCurrencyID());
        setSessionData(session);
    //getSqlMapClientTemplate().insert("logging.insertPair", m);

    }

    public void setDSmrates(Currency c1, Currency c2, Session session)
    {
        c1.setSmrate((Double) getSqlMapClientTemplate().queryForObject("currency.getDSMRate", c1));
        c2.setSmrate((Double) getSqlMapClientTemplate().queryForObject("currency.getDSMRate", c2));
        HashMap m = new HashMap();
        m.put("service_id", Currency.getServiceID());
        m.put("first_id", c1.getCurrencyID());
        m.put("second_id", c2.getCurrencyID());
        setSessionData(session);
    //getSqlMapClientTemplate().insert("logging.insertPair", m);

    }

    public String getNextSessionID()
    {
        return (String) getSqlMapClientTemplate().queryForObject("logging.session_seq");
    }

    public void insertSession(Session session)
    {
        if (session.getSessionID() == null)
        {
            session.setSessionID(getNextSessionID());
        }
        getSqlMapClientTemplate().insert("logging.insertSession", session);
    }


     public void insertErOp(String oper,String opip,String status,String cdate)
    {
        HashMap i = new HashMap();


        i.put("oper", oper);
        i.put("opip", opip);
        i.put("status", status);
        i.put("cdate", cdate);

        getSqlMapClientTemplate().insert("logging.insertErOps", i);

    }


    public void insertLot(Session session)
    {

        getSqlMapClientTemplate().insert("logging.insertLot", session);
    }

    public void setSessionData(Session session)
    {
//        HashMap m = new HashMap();
//        m.put("id", session.getSessionID());
//        getSqlMapClientTemplate().update("logging.setSessionData", m);
    }

    public List<StringString> searchCountryOperators(Country country)
    {
        return getSqlMapClientTemplate().queryForList("main.searchCountryOperators", country);
    }

    public List<City> searchCountryCityCodes(Country country)
    {
        return getSqlMapClientTemplate().queryForList("main.searchCountryCityCodes", country);
    }

    public List<City> searchCityCodes(String cityName)
    {
        return getSqlMapClientTemplate().queryForList("main.searchCityCodes", cityName);
    }

    public List<City> searchCountryCode(String code)
    {
        return getSqlMapClientTemplate().queryForList("main.searchCountryCode", code);
    }

    public List<City> searchCityCode(String code)
    {
        return getSqlMapClientTemplate().queryForList("main.searchCityCode", code);
    }

    public List<Organization> searchOrganizations(Organization org)
    {
        List<Organization> list = getSqlMapClientTemplate().queryForList("main.searchOrganizationsByName", org);

        List<Organization> listTbilisi = new ArrayList<Organization>();
        List<Organization> listNonTbilisi = new ArrayList<Organization>();
        Integer idTbilisi = new Integer(2208);
        for (Organization organization : list)
        {
            if (organization.getAddress().getCityID().equals(idTbilisi))
            {
                listTbilisi.add(organization);
            } else
            {
                listNonTbilisi.add(organization);
            }
        }
        List<Organization> listResult = Utils.sortOrganizations(listTbilisi, org);
        List<Organization> listNonResult = Utils.sortOrganizations(listNonTbilisi, org);
        for (Organization organization : listNonResult)
        {
            listResult.add(organization);
        }

        return listResult;
    }

    public void getOrganizationDetails(Organization result)
    {
        List<MainResultDetail> results = (List<MainResultDetail>) getSqlMapClientTemplate().queryForList("main.getOrganizationDetails", result.getMainID());
        if (results == null)
        {
            results = new ArrayList<MainResultDetail>();
        }
        result.setDetails(results);
    // result.setAddress((Address) getSqlMapClientTemplate().queryForObject("main.searchAddressByID", result.getMainID()));
    }

    public Organization getOrganizationByID(Integer id)
    {
        Organization org = (Organization) getSqlMapClientTemplate().queryForObject("main.getOrganizationByID", id);
        if (org != null)
        {
            getOrganizationDetails(org);
        }
        return org;
    }

    public List<String> findCountryByCurrency(String curr)
    {
        return getSqlMapClientTemplate().queryForList("main.findCountryByCurrency", curr);
    }

    public String getNotemob()
    {
        return (String) getSqlMapClientTemplate().queryForObject("main.getNotemob", null);
    }

    public String getNotesb()
    {
        return (String) getSqlMapClientTemplate().queryForObject("main.getNotesb", null);
    }


    public void fillOrganizationMasterSlaves(Organization org)
    {
        List<Integer> ids = getSqlMapClientTemplate().queryForList("main.fillOrganizationSlaves", org);
        List<Organization> slaves = new ArrayList<Organization>();
        for (Integer id : ids)
        {
            Organization o = getOrganizationByID(id);
            getOrganizationDetails(o);
            slaves.add(o);
        }
        if (slaves.size() > 0)
        {
            org.setSlaves(slaves);
        }
        if (org.getMasterID() != 0)
        {
            org.setMaster((StringString) getSqlMapClientTemplate().queryForObject("main.fillOrganizationMaster", org));
        }
    }

    public void insdiscovery(Discover discover, Session session)
    {
        HashMap i = new HashMap();

// (#sessionID:VARCHAR#,#phone:VARCHAR#,#dtxt:VARCHAR#,#contactphone:VARCHAR#,#dtid#,#recuser:VARCHAR#
        i.put("sessionID", discover.getCallid());
        i.put("phone", discover.getPhone());
        i.put("contactphone", discover.getContactphone());
        i.put("contactperson", discover.getContactperson());
        i.put("dtxt", discover.getDtxt());
        i.put("dtid", discover.getDtid());
        i.put("recuser", session.getUserName());

        getSqlMapClientTemplate().insert("main.insdiscovery", i);

    }

    public void inscharge(int id, Session session)
    {

        HashMap i = new HashMap();

        i.put("service_id", id);
        i.put("sessionID", session.getSessionID());
        i.put("YM", session.getYearMonth());
        getSqlMapClientTemplate().update("logging.inscharge", i);
    }

    public void insorgcharge(int id, Session session,int mainid)
    {

        HashMap i = new HashMap();

        i.put("service_id", id);
        i.put("sessionID", session.getSessionID());
        i.put("YM", session.getYearMonth());
        i.put("mainid", mainid);
        getSqlMapClientTemplate().update("logging.insorgcharge", i);
    }

    public List<Transport> searchTripCriteria(Transport transport)
    {
        List<Integer> result = getSqlMapClientTemplate().queryForList("transport.searchTripCriteria", transport);
        if (result == null || result.size() == 0)
        {
            return null;
        }
        return getSqlMapClientTemplate().queryForList("transport.foundTransports", result);
    }

    public void insertDiscoveryPhone(HashMap map)
    {
        getSqlMapClientTemplate().insert("logging.insertDiscovery", map);
    }

    public Mymobile findMobile(Mymobile mymobile)
    {
        return (Mymobile) getSqlMapClientTemplate().queryForObject("logging.findMobile", mymobile);
    }

    public String getDebts(String phone)
    {
        return (String) getSqlMapClientTemplate().queryForObject("logging.getDebts", phone);
    }

    public List<StringString> getOthersSection()
    {
        return getSqlMapClientTemplate().queryForList("others.getOtherSection");
    }

    public List<StringString> getSitesSection()
    {
        return getSqlMapClientTemplate().queryForList("others.getSiteSection");
    }

    public List<OthersInfo> searchInfo(OthersInfo oth)
    {
        return getSqlMapClientTemplate().queryForList("others.searchInfo", oth);
    }

    public List<OthersInfo> searchSiteInfo(OthersInfo oth)
    {
        return getSqlMapClientTemplate().queryForList("others.searchSite", oth);
    }

    public void logHits(Session session, Integer id, Integer serviceID)
    {
        HashMap<String, Object> map = new HashMap();
        map.put("SERVICE_ID", serviceID);
        map.put("SESSION_ID", session.getSessionID());
        map.put("YM", session.getYearMonth());
        map.put("MAIN_ID", id);
        getSqlMapClientTemplate().insert("logging.insertHit", map);
    }

    public void updtr(Session session, String cphone, String lnote)
    {
        HashMap<String, Object> map = new HashMap();

        map.put("sid", session.getSessionID());
        map.put("cphone", cphone);
        map.put("lnote", lnote);
        getSqlMapClientTemplate().update("main.updtr", map);
    }

    public void updfl(Session session)
    {
        HashMap<String, Object> map = new HashMap();

        map.put("sid", session.getSessionID());

        getSqlMapClientTemplate().update("main.updfl", map);
    }


    public void insertSms(Session session, String txt, int SERVICE_ID)
    {
        if (txt == null)
        {
            return;
        }
        if (txt.length() > 999)
        {
            txt = txt.substring(0, 998);
        }
        HashMap<String, Object> map = new HashMap();

        map.put("TXT", txt);
        map.put("PHONE", session.getPhone());
        map.put("SESSION_ID", session.getSessionID());
        map.put("SERVICE_ID", SERVICE_ID);
        
        getSqlMapClientTemplate().update("logging.insertSMS", map);

    }

    public void insertMobName(Session session, String dnm, int sex)
    {
        if (session.getPhone() == null || dnm==null)
        {
            return;
        }

        HashMap<String, Object> map = new HashMap();

        map.put("USN", session.getUserName());
        map.put("MOB", session.getPhone());
        map.put("DNM", dnm);
        map.put("SEX", sex);
        getSqlMapClientTemplate().insert("logging.insertMN", map);

    }

}

